﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace euler
{
    class Program
    {
        static void Main(string[] args)
        {
            //hello world
            List<int> P3 = new List<int>();
            List<int> P4 = new List<int>();
            List<int> P5 = new List<int>();
            List<int> P6 = new List<int>();
            List<int> P7 = new List<int>();
            List<int> P8 = new List<int>();

            int temp=0;
            bool ok=false;
            int i = 1;
            while (!ok)
            {
                ok = true;
                temp = (i * (i + 1)) / 2;
                if(temp<10000)
                {
                    if (temp>1000)
                        P3.Add(temp);
                    ok = false;
                }
                temp = i*i;
                if (temp < 10000)
                {
                    if (temp > 1000)
                        P4.Add(temp);
                    ok = false;
                }
                temp = (i*(3*i-1))/2;
                if (temp < 10000)
                {
                    if (temp > 1000)
                        P5.Add(temp);
                    ok = false;
                }
                temp = i*(2*i-1);
                if (temp < 10000)
                {
                    if (temp > 1000)
                        P6.Add(temp);
                    ok = false;
                }
                temp = (i * (5 * i - 3)) / 2;
                if (temp < 10000)
                {
                    if ( temp > 1000)
                        P7.Add(temp);
                    ok = false;
                }
                temp = i*(3*i-2);
                if (temp < 10000)
                {
                    if (temp > 1000)
                        P8.Add(temp);
                    ok = false;
                }
                if (ok)
                    break;
                i++;
            }
            foreach (int p3 in P3)
            {
                foreach (int p4 in P4)
                {

                    if (p4.ToString().Substring(0, 2) == p3.ToString().Substring(2, 2))
                    {
                        foreach (int p5 in P5)
                        {

                            if (p5.ToString().Substring(0, 2) == p4.ToString().Substring(2, 2))
                            {
                                foreach (int p6 in P6)
                                {

                                    if (p6.ToString().Substring(0, 2) == p5.ToString().Substring(2, 2))
                                    {
                                        foreach (int p7 in P7)
                                        {

                                            if (p7.ToString().Substring(0, 2) == p6.ToString().Substring(2, 2))
                                            {
                                                foreach (int p8 in P8)
                                                {

                                                    if (p3.ToString().Substring(0, 2) == p8.ToString().Substring(2, 2))
                                                    {
                                                        Console.WriteLine(p3);
                                                        Console.WriteLine(p4);
                                                        Console.WriteLine(p5);
                                                        Console.WriteLine(p6);
                                                        Console.WriteLine(p7);
                                                        Console.WriteLine(p8);

                                                    }
                                                }


                                            }
                                        }


                                    }
                                }


                            }
                        }


                    }
                }

            }
        }
    }
}
